package com.dungnt.vtime.utils;

import android.content.Context;
import android.graphics.Typeface;

public class Utils {
	public static final StringBuilder sb = new StringBuilder();

/**
	 * Function: Get Font from Asset Folder
	 * 
	 * @param c
	 * @param fontName
	 * @return TypeFace
	 */
	public static Typeface getFontFromAssets(Context c, String fontName) {
		return Typeface.createFromAsset(c.getAssets(), fontName);
	}

	/**
	 * Function: Convert from Milliseconds to String
	 * 
	 * @param time
	 *            (ms)
	 * @return String ( Example: 01:00:12.789 )
	 */
	public static String updateTimer(long time, boolean isShowMilliseconds) {
		long secs = (long) (time / 1000);
		long mins = (long) ((time / 1000) / 60);
		long hrs = (long) (((time / 1000) / 60) / 60);

		secs = secs % 60;
		String seconds = String.valueOf(secs);
		if (secs == 0) {
			seconds = "00";
		}
		if (secs < 10 && secs > 0) {
			seconds = "0" + seconds;
		}
		mins = mins % 60;
		String minutes = String.valueOf(mins);
		if (mins == 0) {
			minutes = "00";
		}
		if (mins < 10 && mins > 0) {
			minutes = "0" + minutes;
		}
		String hours = String.valueOf(hrs);
		if (hrs == 0) {
			hours = "00";
		}
		if (hrs < 10 && hrs > 0) {
			hours = "0" + hours;
		}
		long msecs = (long) (time - hrs * 60 * 60 * 1000 - mins * 60 * 1000 - secs * 1000);
		String milliseconds = String.valueOf(msecs);
		if (milliseconds.length() == 1) {
			milliseconds = "00" + milliseconds;
		} else if (milliseconds.length() == 2) {
			milliseconds = "0" + milliseconds;
		}
		return (isShowMilliseconds ? ("" + hours + ":" + minutes + ":"
				+ seconds + "." + milliseconds) : ("" + hours + ":" + minutes
				+ ":" + seconds));
	}
	
	public static String concat(Object... objects) {
		sb.setLength(0);
		for (Object obj : objects) {
			sb.append(obj);
		}
		return sb.toString();
	}
}
